package pwcms;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.mahout.cf.taste.pwcms.common.PWCMSRecomender;

/**
 * Created by IntelliJ IDEA.
 * User: sudharaka
 * Date: Jun 3, 2011
 * Time: 3:49:34 AM
 * To change this template use File | Settings | File Templates.
 */
public class SampleApp extends HttpServlet {

@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/*
* Get the value of form parameter
*/
String name = request.getParameter("name");
String itemId = request.getParameter("itemId");
String preferenceValue = request.getParameter("preferenceValue");
String preferenceType = request.getParameter("preferenceType");
String welcomeMessage = "User Id "+name + "<br/>" + "Item Id " + itemId + "<br/>" + "Preference Value " + preferenceType +
        "<br/>" + "commited To DB";

 PWCMSRecomender recomender = new PWCMSRecomender();
recomender.setPreference(new Integer(name).longValue() , new Integer(itemId).longValue(), new Integer(preferenceValue).floatValue(),preferenceType);
    

request.setAttribute("userID", name);
request.setAttribute("itemID", itemId);
request.setAttribute("PreferenceValue", new Integer(preferenceValue));
request.setAttribute("PreferenceType", preferenceType);

String destination = "/setPreferenceResult.jsp";

RequestDispatcher rd = getServletContext().getRequestDispatcher(destination);
rd.forward(request, response);

  //  recomender.setPreference(30,6,5,"like");
/*
/*
* Set the content type(MIME Type) of the response.
*/
//response.setContentType("text/html");
//
//PrintWriter out = response.getWriter();
///*
//* Write the HTML to the response
//*/
//out.println("<html>");
//out.println("<head>");
//out.println("<title> Sample Application For testing PWCMS module</title>");
//out.println("</head>");
//out.println("<body>");
//out.println("<h4>"+welcomeMessage+"</h4>");
//
//out.println("</body>");
//out.println("</html>");
//out.close();

}


public void destroy() {

}
} 
